/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forensicsGUI;

import java.io.File;

/**
 *
 * @author marc
 */
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Date;
import javax.swing.JTextField;

/**
 * Class is used to fetch statistics about a given task.
 * @author marc
 */
public final class fetchStatistics extends TimerTask {

    private JTextField threadsField;
    private JTextField executionField;
    private int pid = 0;
    private ErrorInstanceLogger pidGather = null;

    public void setPid(ErrorInstanceLogger pidGather) {
        this.pidGather = pidGather;
    }

    public void setTextExecutionField(JTextField field) {
        executionField = field;
    }

    public void setTextThreadsField(JTextField field) {
        threadsField = field;
    }

    /**
     * Implements TimerTask's abstract run method.
     */
    public void run() {
        //toy implementation
        try {
            pid = pidGather.getPid();
            if (pid == 0) {
                throw new Exception();
            }
            File f = new File("/proc/" + pid + "/task/");

            if (f.exists() && f.isDirectory()) {
                File[] children = f.listFiles();
                threadsField.setText(children.length + "");
            }
        } catch (Exception e) {
            threadsField.setText("-");
        }
    }
}
